export const prepay = (data: any, order: any, JumpUrl: string, paymentType: string) => {
	if (order.paymentPrice === 0) {
		uni.reLaunch({
			url: JumpUrl,
		});
	} else {
		// #ifdef MP-WEIXIN
		uni.requestPayment<any>({
			provider: 'wxpay',
			timeStamp: data.timeStamp,
			nonceStr: data.nonceStr,
			package: data.packageValue,
			signType: data.signType,
			paySign: data.paySign,
			success: function (res) {
				uni.reLaunch({
					url: JumpUrl,
				});
			},
			fail: function (err) {
				uni.showModal({
					title: '提示',
					content: JSON.stringify(err),
					success(res) {
						uni.reLaunch({
							url: JumpUrl,
						});
					},
				});
			},
		});
		// #endif
		// #ifdef MP-ALIPAY
		uni.requestPayment({
			provider: 'alipay',
			orderInfo: data.tradeNo,
			success: function (res) {
				if (res.resultCode != '9000') {
					uni.showModal({
						title: '提示',
						content: res.memo,
						success(res) {},
					});
				} else {
					uni.reLaunch({
						url: JumpUrl,
					});
				}
			},
			fail: function (err) {
				uni.showModal({
					title: '提示',
					content: JSON.stringify(err),
					success(res) {},
				});
			},
		});
		// #endif

		// #ifdef APP-PLUS
		let orderInfo = {
			appid: data.appid,
			noncestr: data.noncestr,
			package: data.packageValue,
			partnerid: data.partnerId,
			prepayid: data.prepayId,
			timestamp: data.timestamp,
			sign: data.sign,
		};
		if (paymentType == '1') {
			uni.requestPayment({
				provider: 'wxpay',
				orderInfo: JSON.stringify(orderInfo),
				success(res) {
					uni.reLaunch({
						url: JumpUrl,
					});
				},
				fail(e) {
					uni.showModal({
						title: '提示',
						content: JSON.stringify(e),
						success(res) {},
					});
				},
			});
		} else {
			uni.requestPayment({
				provider: 'alipay',
				orderInfo: data.body,
				success(res) {
					uni.reLaunch({
						url: JumpUrl,
					});
				},
				fail(e) {
					uni.showModal({
						title: '提示',
						content: JSON.stringify(e),
						success(res) {},
					});
				},
			});
		}

		// #endif
	}
};
